<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>频率选择</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/allApp.css" />
		<link rel="stylesheet" href="../css/css.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">频率选择</h1>
			<!--<a class="mui-icon-right-nav mui-pull-right">确定</a>-->
		</header>
		<div class="mui-content">
			<ul class="mui-table-view mui-table-view-radio" id="content">
				<li class="mui-table-view-cell " v-for="item in data" :data-type="(item.rate)">
					<a class="mui-navigate-right">
						{{handleType(item.rate)}}
					</a>
				</li>
			</ul>
			<div class="btn">
				<button type="button" class="mui-btn mui-btn-primary mui-col-sm-12 mui-col-xs-12" id="sure">确定</button>
			</div>
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../../js/vue.js"></script>
		<script src="../../../js/jquery-3.1.1.js"></script>
		<script type="text/javascript" src="../../../js/mkeyplus.base.xunjian.js"></script>
		<script src="./../js/websql.js"></script>
		<script>
			mui.init()
			var scancode;
			var opener;
			var rateid;
			var index;
			
			window.vm = new Vue({
				el: "#content",
				data: {
					data: []
				},
				methods:{
					handleType(type){
						var ratetext = '';
						if(type == '0'){
							ratetext = '天'
						}else if(type == '1'){
							ratetext = '周'
						}else if(type == '2'){
							ratetext = '月'
						}else if(type == '3'){
							ratetext = '季'
						}else if(type == '4'){
							ratetext = '半年'
						}
						return ratetext;
					}
				}
			});
			
			
			mui.plusReady(function() {
				self = plus.webview.currentWebview();
				scancode = self.scan;
				opener = self.opener()
				opener.close('none');
				console.log(localStorage.getItem("curentTime"));
				if(scancode.indexOf("\"")!=-1){
					scancode=scancode.replace(/\"/g, "");
				}
//				if(typeof(scancode) == "undefined")
				document.querySelector('#sure').addEventListener('tap', function() {
					if (plus.networkinfo.getCurrentType()  ==  plus.networkinfo.CONNECTION_NONE)  {
						websqlOpenDB();               
						console.log("查找全部数据");    
						websqlGetAData(sbInfoTable, scancode, index);
					} else {
						sure();
					}
				})
				getSbRateList();

			});
			
			function getSbRateList(){
				mui.baseApp.httpRequst('/api/v2/sbxj/getSbRateList', {
					scancode: scancode
				}, function(res) {
					console.log('res=='+JSON.stringify(res));
					if(res.data.length == 1){
						index = res.data[0].rate;
						vm.data = res.data;
						console.log('vm.data=',vm.data);
						sure();
					}else{
						vm.data = res.data;
					}
				}, function() {
					console.log("获取列表项失败");
				});
			}

			function sure() {
				//				扫面时间
				var myDate = new Date(); //保存的日期时间
				var year = myDate.getFullYear(); //年
				var month = myDate.getMonth() + 1;
				var day = myDate.getDate();
				var hour = myDate.getHours(); //获取当前小时数(0-23)
				var mins = myDate.getMinutes(); //获取当前分钟数(0-59)
				var second = myDate.getSeconds(); //获取当前秒数(0-59)
				var months = (month < 10) ? ("0" + month) : month;
				var days = (day < 10) ? ("0" + day) : day;
				var hours = (hour < 10) ? ("0" + hour) : hour;
				var minss = (mins < 10) ? ("0" + mins) : mins;
				var seconds = (second < 10) ? ("0" + second) : second;
				console.log("月。。" + month + "日" + day.length)
				var smTime = year + "-" + months + "-" + days + " " + hours + ":" + minss + ":" + seconds;
				console.log(smTime);
				if(!index){
					index = $(".mui-content li.mui-selected").attr('data-type') == -1 ? index : $(".mui-content li.mui-selected").attr('data-type');
				}
				console.log(index);
				if(index == "5") {
					mui.openWindow({
						id: "specialxunjian.html",
						url: "specialxunjian.html",
						/*waiting: {
							autoShow: false, //自动显示等待框，默认为true
						},*/
						extras: {
							scancode: scancode,
							index: index,
							smTime: smTime
						}
					});
				} else {
					console.log('index='+index);
					mui.openWindow({
						id: "xianchangxunjian.html",
						url: "../xianchangxunjian.html",
						extras: {
							scancode: scancode,
							index: index,
							smTime: smTime,
							from:'shebei'
						}
					});
				}

			}
			//			获取第一个表数据
			function success(sbInfo_) {
				var sbInfo_list = sbInfo_.List;
				console.log('sbInfo_list' + JSON.stringify(sbInfo_list));
				name = sbInfo_list.name;
				rateid = sbInfo_list.rateid;
				websqlGetAData_(jcxInfoTable, rateid);
			}
			//			获取第二个表数据
			function success_(jcxInfo) {
				var jcxInfo_list = jcxInfo.List;
				if(jcxInfo.List.length == 0) {
					mui.toast('当前频率下无数据');
				} else {
					sure();
				}

			}
		</script>
	</body>

</html>